package de.tapps.brainstorming;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.os.AsyncTask;

public class Enabled extends AsyncTask<String, Integer, String> {
		private MainActivity activity = new MainActivity();
		private GUI gui;
		public Enabled(MainActivity act){
			activity = act;
		}
		String inputLine;
		String str = "";
		String resString;
		@Override
		protected String doInBackground(String... arg0) {
			new Thread(new Runnable() {
				public void run() {
					
					            HttpClient httpclient = new DefaultHttpClient(); // Create HTTP Client
					            HttpGet httpget = new HttpGet("http://t-apps-online.de/BrainStorming/program-disabled.php"); // Set the action you want to do
					            HttpResponse response;
								try {
									response = httpclient.execute(httpget);
									  HttpEntity entity = response.getEntity(); 
							            InputStream is = entity.getContent(); // Create an InputStream with the response
							            BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
							            StringBuilder sb = new StringBuilder();
							            String line = null;
							            while ((line = reader.readLine()) != null) // Read line by line
							                sb.append(line + "\n");

							            resString = sb.toString(); // Result is here
							            activity.runOnUiThread(new Runnable() {
											public void run() {
												if (resString.indexOf("1") != -1){
													gui.showMessage("The App was disabled by Programmer.");
activity.finish();
}
											}
										});
							            is.close();
								} catch (ClientProtocolException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} catch (IOException e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								} // Executeit
					          
					           
					            
					        
					
				
				}}).start();
			
			return "";
		}
		
	}

